<template>
  <zy-model :show="isShow" @close="closeCrowdModel" @submit="submitCrowd" width="900">
    <div class="model-table-box">
      <zy-title>新增合作企业</zy-title>
      <!--    筛选条件-->
      <div class="search-box">
        <div class="search-item">
          <div class="search-label">企业名称</div>
          <el-input v-model="form.company_name" placeholder="请输入企业名称"></el-input>
        </div>
        <div class="search-item">
          <div class="search-label">企业类型</div>
          <el-select v-model="form.type" filterable placeholder="请选择" collapse-tags>
            <el-option v-for="option in optionList" :key="option.value" :label="option.label"
                       :value="option.value"></el-option>
          </el-select>
        </div>
        <div class="btnArea">
          <zy-button @click="getData(true)">重置</zy-button>
          <zy-button @click="getData(false)" type="primary">查询</zy-button>
        </div>
      </div>
      <!--    列表-->
      <div class="table_list">
        <el-table :data="tableData" tooltip-effect="dark" :highlight-current-row="true"
                  v-loading="loading" :show-header="true" @row-click="rowClick">
          <el-table-column fixed="left" align="center" type="index" label="序号" width="60"></el-table-column>
          <el-table-column prop="company_name" align="center" label="企业名称" width="auto"></el-table-column>
          <el-table-column prop="type_desc" align="center" label="企业类型" width="80"></el-table-column>
          <el-table-column prop="organization_code" align="center" label="统一社会信用代码" width="240"></el-table-column>
          <el-table-column prop="legal_person" align="center" label="法人" width="auto"></el-table-column>
          <el-table-column prop="legal_phone" align="center" label="法人联系方式" width="auto"></el-table-column>
        </el-table>
      </div>
      <div class="paging">
        <el-pagination background layout="total, sizes,prev, pager, next,jumper" :page-sizes="[10, 20, 30, 50]"
                       @size-change="(page_size) => {this.form.page_size = page_size;this.getData()}"
                       @current-change="(page_size) => {this.form.page_start = page_size;this.getData()}"
                       :page-size="form.page_size" :total="total" :current-page="form.page_start"></el-pagination>
      </div>
    </div>
  </zy-model>
</template>

<script>

	export default {
		name: "companyModel",
		props: {
			isShow: {
				type: Boolean,
				default: false
			}
		},
		data() {
			return {
				form: {
					company_name: "",
					type: "",
					page_start: 1,
					page_size: 10
				},
				loading: false,
				tableData: [],
				total: 0,
				selectedCompany: {},
				optionList: [
					{label: '全部', value: ''},
					{label: '物流', value: '0'},
					{label: '快递', value: '1'},
				]
			};
		},
		computed: {
			postData() {
				let data = {
					...this.form,
					pagination: {
						page_start: this.form.page_start,
						page_size: this.form.page_size
					}
				};
				return data;
			},
		},
		watch: {},
		components: {},
		methods: {
			rowClick(val) {
				this.selectedCompany = {...val};
			},
			getData(isRefresh) {
				if (isRefresh) {
					this.form = {
						company_name: "",
						type: "",
						page_start: 1,
						page_size: 10
					}
				}
				this.loading = true;
				this.$axios.post(this.$api.c_getNotCompanyList, this.postData).then(res => {
					let {code, msg, data} = res;
					this.loading = false;
					if (code == 200) {
						let list = data.list || [];
						this.tableData = list.filter(item => {
							return item;
						});

						this.total = data.pagination.total_count || 0;
					} else {
						this.$message.error(msg);
						this.tableData = [];
					}
				}).catch(ret => {
					this.loading = false;
					this.$message.error(ret.msg || "服务繁忙，请稍后再试");
				});
			},
			closeCrowdModel() {
				this.$emit('close')
			},
			submitCrowd() {
				this.$emit('submit', this.selectedCompany);
			}
		},
		mounted() {
			this.getData();
		},
		created() {
		}
	}
</script>

<style scoped lang="less">
  @import "../../../../style/common/common";

  .model-table-box {

    .search-box {
      display: flex;
      align-items: center;
      padding: 0 @commonPaddingOutside;
      justify-content: space-between;
      margin-bottom: @commonPaddingOutside;

      .search-item {
        display: flex;
        align-items: center;

        .search-label {
          font-size: 14px;
          color: @fontColor;
          margin-right: @commonPaddingOutside;
          width: 60px;
        }

        .el-input {
          width: 240px;
          height: 40px;
          border-radius: 4px;

          .el-input__inner {
            flex: 1;
            background: rgba(216, 216, 216, 0);
            border-radius: 4px;
            border: 1px solid #C7CBD1;
            color: @fontColor;
          }
        }
      }


      .btnArea {
        display: flex;
        justify-content: flex-end;
        align-items: center;

        button {
          margin-left: 28px;
        }
      }
    }

    .table_list {
      padding: 0 24px;
      margin-bottom: 16px;
      max-height: 360px;
      overflow-y: auto;

      /deep/ .el-table__row {
        cursor: pointer;
      }

      /deep/ .el-table__body tr.current-row > td,
      /deep/ .el-table__body tr.hover-row.current-row > td,
      /deep/ .el-table__body tr.hover-row.el-table__row--striped.current-row > td,
      /deep/ .el-table__body tr.hover-row.el-table__row--striped > td,
      /deep/ .el-table__body tr.hover-row > td {
        background-color: rgba(0, 119, 251, 0.2) !important;
      }

      /deep/ .el-table--enable-row-hover .el-table__body tr:hover > td {
        background-color: rgba(0, 119, 251, 0.2) !important;
      }

      /deep/ .el-table--enable-row-hover .el-table__body tr.current-row td {
        background-color: rgba(0, 119, 251, 0.2) !important;
      }
    }

    .paging {
      text-align: center;
      margin-top: 16px;

      /deep/ .el-pagination {
        color: @fontColor;

        /deep/ .el-pagination__total {
          font-size: 12px;
          color: @fontColor;
        }

        /deep/ .el-pagination__sizes {
          font-size: 12px;
          color: @fontColor;
        }

        /deep/ .el-input__inner {
          border: 1px solid #C7CBD1;
          color: @fontColor;
          border-radius: 4px;
          font-size: 12px;
        }

        /deep/ .el-pager li {
          font-size: 12px;
          font-weight: normal;
        }

        /deep/ .el-pager li.active {
          background-color: @allPrimaryColor;
        }
      }
    }
  }
</style>
